package netty.buf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * Created by IntelliJ
 * Author:熊磊
 */
public class ByteBuf1 {
    public static void main(String[] args) {
        //可边读边写 , 初始化 readIndex 和 writeIndex 都等于 0
        ByteBuf buffer = Unpooled.buffer(10);

        for (int i = 0; i < 10; i++) {
            buffer.writeByte(i);
            //System.out.println(buffer.readByte());
        }
        //buffer.resetWriterIndex();
        System.out.println("capacity = " + buffer.capacity());

        for (int i = 0; i < buffer.capacity(); i++) {
            //System.out.println(buffer.getByte(i));

            //实际上readByte()方法 只能获取到 writeIndex以内的数
            System.out.println(buffer.readByte());
        }
    }
}
